package com.youlu.campus.website.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.website.entity.ActivityType;
import com.youlu.campus.website.entity.ActivityTypePageQuery;
import com.youlu.campus.website.service.ActivityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 活动简介类型
 */
@RestController
@RequestMapping("/website/activity/type")
public class ActivityTypeController {

    @Autowired
    private ActivityTypeService activityTypeService;

    /**
     * 创建或更新标题类型
     *
     * @param activityType 标题类型对象
     * @return 响应结果
     */
    @PostMapping("/save")
    public QResult<ActivityType> saveActivityType(@RequestBody ActivityType activityType) {
        ActivityType saved = activityTypeService.save(activityType);
        return QResult.success(saved);
    }

    /**
     * 分页查询标题类型
     *
     * @param pageQuery 标题类型对象
     * @return 响应结果
     */
    @PostMapping("/find-page")
    public QResult<Page<ActivityType>> findByPage(@RequestBody ActivityTypePageQuery pageQuery) {
        Page<ActivityType> page = activityTypeService.findByPage(pageQuery);
        return QResult.success(page);
    }

    /**
     * 根据ID查询标题类型
     *
     * @param id 主键ID
     * @return 标题类型
     */
    @GetMapping("/info")
    public QResult<ActivityType> getActivityTypeById(@RequestParam String id) {
        ActivityType typeById = activityTypeService.getTypeById(id);
        return QResult.success(typeById);
    }

    /**
     * 查询所有标题类型
     *
     * @return 标题类型列表
     */
    @GetMapping("/find-enable")
    public QResult<List<ActivityType>> listEnabledType() {
        List<ActivityType> activityTypes = activityTypeService.listEnabledType(100);
        return QResult.success(activityTypes);
    }

    /**
     * 删除标题类型
     *
     * @param activityType 主键ID
     * @return 响应结果
     */
    @PostMapping("/delete")
    public QResult<Void> deleteActivityType(@RequestBody ActivityType activityType) {
        activityTypeService.delete(activityType.getId());
        return QResult.success();
    }
}
